using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Dcms.BLL;
using Dcms.Model;
using Dcms.Common;
using Dcms.TempLate;
using BaseLib;
using OleDbBaseLib;

public partial class UserControl_SysControl_NextPrev : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string NextAndPrev = string.Empty;
        int pId = DcmsRequest.GetQueryInt("Id",0);
        Dcms_ProductsModel pM = new Dcms_ProductsModel();
        Dcms_ProductsBLL pB = new Dcms_ProductsBLL();
        pM = pB.GetModelByID(pId);
        int CateId = pM.Pro_CateID;

        string PrevSql = "Select Top 1 Pro_ID,Pro_Name From Dcms_Products Where Pro_State='1' And Pro_CateID=" + CateId + " And Pro_Order>" + pM.Pro_Order.ToString()+ " Order By Pro_Order Asc";
        string NextSql = "Select Top 1 Pro_ID,Pro_Name From Dcms_Products Where Pro_State='1' And Pro_CateID=" + CateId + " And Pro_Order<" + pM.Pro_Order.ToString()+ " Order By Pro_Order Desc";
        DataTable dtNext = OleDbHelper.CreateDataSet(NextSql).Tables[0];
        DataTable dtPrev = OleDbHelper.CreateDataSet(PrevSql).Tables[0];
        if (dtPrev.Rows.Count > 0)
        {
            NextAndPrev = "[<a href=\"/" + hfd_Url.Value + "?Id=" + dtPrev.Rows[0][0] + "\">" + hfd_PrevName.Value + "</a>] &nbsp; &nbsp; ";
        }
        else
        {
            NextAndPrev = "[" + hfd_PrevName.Value + "] &nbsp; &nbsp; &nbsp; ";
        }
        NextAndPrev = NextAndPrev + "[<a href=\"/" + hfd_BackUrl.Value + "?CateId=" + CateId + "\">" + hfd_BackName.Value + "</a>] &nbsp; &nbsp; ";
        if (dtNext.Rows.Count > 0)
        {
            NextAndPrev = NextAndPrev + " [<a href=\"/" + hfd_Url.Value + "?Id=" + dtNext.Rows[0][0] + "\">" + hfd_NextName.Value + "</a>] ";
        }
        else
        {
            NextAndPrev = NextAndPrev + "[" + hfd_NextName.Value + "] ";
        }

        Literal1.Text = NextAndPrev;
    }
}
